package self;

import java.util.ArrayList;
import java.util.List;

public class Speaker implements Speakable {

	private String content;
	//The speaker's  listeners list.
	private List<Object>  listenerList;
	
	public Speaker() {
		this.content="";
		this.listenerList = new ArrayList<Object>();
	}

	public void setContent(String content){
		this.content = content;
	}
	
	
	@Override
	public void addLister(Listenable listener) {
       listenerList.add(listener);
	}

	@Override
	public void removeLister(Listenable listener) {
		  int i = listenerList.indexOf(listener);
		  listenerList.remove(i);
	}

	@Override
	public void notice() {
		notice(null);
	}
	
	public void notice(Listenable oneSpecialListener){
	  if(null == oneSpecialListener){
	   //Notice all listeners.
		for(int index =0; index < listenerList.size(); index++){
			Listenable  tempListener = (Listenable) listenerList.get(index);
			tempListener.repeatReceiveInfo(content);
		}
	  }else{
		  oneSpecialListener.repeatReceiveInfo(content);
	  }
	}

}
